package com.get;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.add.Job1;
import com.add.Job2;
import com.jdbcUtil.JDBCUtil;

public class Job2Impl {
	public ArrayList<Job2> getBiList(int postid) {
		ArrayList<Job2> ciList=new ArrayList<Job2>();
		Connection Conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Conn = JDBCUtil.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		// 创建一个可以滚动的只读的SQL语句对象
		try {
			stmt = Conn.createStatement(
					java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
					java.sql.ResultSet.CONCUR_READ_ONLY);
		} catch (SQLException e) {
			e.printStackTrace();
		}// 准备SQL语句
		String sql="SELECT *  FROM jobtype2 where postid="+postid+";";
		// 执行SQL语句并获取结果集
		try {
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				Job2 j2=new Job2();
				j2.setId(rs.getInt("jobid"));
				j2.setJobName(rs.getString("jobname"));
				j2.setJobType(rs.getString("jobtype"));
				j2.setNotcie(rs.getString("notice"));
				j2.setPayType(rs.getString("paytype"));
				j2.setPlace(rs.getString("place"));
				j2.setPostId(rs.getInt("postid"));
				j2.setSalary(rs.getInt("salary"));
				j2.setState(rs.getInt("jobstate"));
				j2.setDate(rs.getString("date"));
				j2.setTime1(rs.getString("time1"));
				j2.setTime2(rs.getString("time2"));
				j2.setTime3(rs.getString("time3"));
				j2.setNotcie(rs.getString("notice"));
				ciList.add(j2);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return ciList;
		
	}
	//按照工作id查询
		public Job2 getJob1(int Jobid){
			Job2 j2=new Job2();
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try{
				conn=JDBCUtil.getConnection();
				String sql="select * from jobtype2 where jobid="+Jobid+";";
				ps=conn.prepareStatement(sql);
				rs=ps.executeQuery();
				if(rs.next()){
					j2.setId(rs.getInt("jobid"));
					j2.setJobName(rs.getString("jobname"));
					j2.setJobType(rs.getString("paytype"));
					j2.setNotcie(rs.getString("notice"));
					j2.setPayType(rs.getString("paytype"));
					j2.setPlace(rs.getString("place"));
					j2.setPostId(rs.getInt("postid"));
					j2.setSalary(rs.getInt("salary"));
					j2.setState(rs.getInt("jobstate"));
					j2.setDate(rs.getString("date"));
					j2.setTime1(rs.getString("time1"));
					j2.setTime2(rs.getString("time2"));
					j2.setTime3(rs.getString("time3"));
					return j2;
				}
			}catch(Exception e){
				System.out.println(e);
			}finally{
				JDBCUtil.free(conn, ps, rs);
			}
			return null;
		}
}
